<?php
require(__MODEL_GEN__ . '/PersonGen.class.php');

/**
 * The Person class defined here contains any
 * customized code for the Person class in the
 * Object Relational Model.  It represents the "person" table
 * in the database, and extends from the code generated abstract PersonGen
 * class, which contains all the basic CRUD-type functionality as well as
 * basic methods to handle relationships and index-based loading.
 *
 * @package My QCubed Application
 * @subpackage DataObjects
 *
 */
class Person extends PersonGen {

    public function __toString() {
        return sprintf('%s %s',  $this->FirstName, $this->LastName);
    }

    public static function LoadArrayByOrgArray(QQCondition $objConditions=null, $objOptionalClauses = null) {
        $ArrayOrg= Person::GetArrayMyOrllAllPerm();
        try {
            return Person::QueryArray(
                    QQ::AndCondition(
                    QQ::OrCondition(
                    QQ::In(QQN::Person()->OrgId, $ArrayOrg),
                    QQ::IsNull(QQN::Person()->OrgId)
                    ),
                    $objConditions),

                    $objOptionalClauses);
        } catch (QCallerException $objExc) {
            $objExc->IncrementOffset();
            throw $objExc;
        }
    }
    public static function CountByOrgArray(QQCondition $objConditions=null) {
        $ArrayOrg= Person::GetArrayMyOrllAllPerm();
        return Person::QueryCount(
                QQ::AndCondition(
                QQ::OrCondition(
                QQ::In(QQN::Person()->OrgId, $ArrayOrg),
                QQ::IsNull(QQN::Person()->OrgId)
                ),
                $objConditions)
        );
    }


    Public static function  GetArrayMyOrllAllPerm(){
        $Orgs = Org::LoadArrayMyOrgAllPerm();
        $ArrayOrg= array();
        if ( ! empty ($Orgs) ) {
            foreach ($Orgs as $Org)
                $ArrayOrg[] = $Org->Id;
        }
        return $ArrayOrg;
    }


    public static function CheckPersonPerm($PersonId) {
        $ArrayOrg= Person::GetArrayMyOrllAllPerm();
        try {
            return Person::QueryArray(
                    QQ::AndCondition(
                        QQ::OrCondition(
                            QQ::In(QQN::Person()->OrgId , $ArrayOrg),
                            QQ::IsNull(QQN::Person()->OrgId)
                    ),
                    QQ::Equal(QQN::Person()->Id,$PersonId )
            ));
        } catch (QCallerException $objExc) {
            $objExc->IncrementOffset();
            throw $objExc;
        }
    }
}
?>